package database

import "time"

// Document 文档表
type Document struct {
	ID         int64     `gorm:"column:id;primaryKey"`
	ParentID   int64     `gorm:"column:parent_id"`
	Level      int       `gorm:"column:level"`
	Ancestors  string    `gorm:"column:ancestors"`
	Title      string    `gorm:"column:title"`
	Author     int64     `gorm:"column:author"`
	Content    string    `gorm:"column:content"`
	CreateTime time.Time `gorm:"column:create_at"`
	UpdateTime time.Time `gorm:"column:update_at"`
}

func (d *Document) TableName() string {
	return "document"
}

// GroupPermission 组权限
type GroupPermission struct {
	ID             int        `json:"id" gorm:"column:id;primaryKey"`
	ResourceType   string     `json:"resourceType" gorm:"column:resource_type"`
	PermissionType string     `json:"permissionType" gorm:"column:permission_type"`
	ResourceID     int64      `json:"resourceId" gorm:"column:resource_id"`
	GroupID        int64      `json:"groupId" gorm:"column:group_id"`
	CreateTime     *time.Time `json:"createTime,omitempty" gorm:"column:createTime"`
}

func (d *GroupPermission) TableName() string {
	return "group_permission"
}

// UserPermission 用户维度权限
type UserPermission struct {
	ID             int        `json:"id" gorm:"column:id;primaryKey"`
	ResourceType   string     `json:"resourceType" gorm:"column:resource_type"`
	PermissionType string     `json:"permissionType" gorm:"column:permission_type"`
	ResourceID     int64      `json:"resourceId" gorm:"column:resource_id"`
	UserId         int64      `json:"userId" gorm:"column:user_id"`
	CreateTime     *time.Time `json:"createTime,omitempty" gorm:"column:createTime"`
}

func (d *UserPermission) TableName() string {
	return "user_permission"
}

// User 用户表
type User struct {
	ID         int64     `json:"id" gorm:"column:id;primaryKey"`
	NickName   string    `json:"nickName,omitempty" gorm:"column:nick_name"`
	UserName   string    `json:"userName,omitempty" gorm:"column:user_name"`
	Password   string    `json:"password,omitempty" gorm:"column:password"`
	CreateTime time.Time `json:"createTime,omitempty" gorm:"column:create_time"`
	UpdateTime time.Time `json:"updateTime,omitempty" gorm:"column:update_time"`
	Avatar     string    `json:"avatar,omitempty" gorm:"column:avatar"`
	Email      string    `json:"email,omitempty" gorm:"column:email"`
	Profile    string    `json:"profile,omitempty" gorm:"column:profile"`
}

func (d *User) TableName() string {
	return "user"
}

// Group 用户组表
type Group struct {
	ID         int64     `json:"id" gorm:"column:id;primaryKey"`
	Name       string    `json:"name,omitempty" gorm:"column:name"`
	Profile    string    `json:"profile,omitempty" gorm:"column:profile"`
	CreatorID  int64     `json:"creatorId,omitempty" gorm:"column:creator_id"`
	CreateTime time.Time `json:"createTime,omitempty" gorm:"column:create_time"`
	Type       int       `json:"type,omitempty" gorm:"column:type"`
}

func (d *Group) TableName() string {
	return "groups"
}

// UserGroup 用户/组关系表
type UserGroup struct {
	GroupID    int64     `json:"groupId" gorm:"column:group_id"`
	UserID     int64     `json:"userId,omitempty" gorm:"column:user_id"`
	CreateTime time.Time `json:"createTime,omitempty" gorm:"column:createTime"`
}

func (d *UserGroup) TableName() string {
	return "user_group"
}

// Session 会话表
type Session struct {
	ID             string    `json:"id" gorm:"column:id;primaryKey"`
	UserID         int64     `json:"userId" gorm:"column:user_id"`
	Groups         string    `json:"groups" gorm:"column:Groups"`
	CreateTime     time.Time `json:"createTime" gorm:"column:create_time"`
	ExpirationTime time.Time `json:"expirationTime" gorm:"column:expiration_time"`
}

func (d *Session) Session() string {
	return "sessions"
}

// Api 接口
type Api struct {
	ID         int64  `json:"id" gorm:"column:id;primaryKey"`
	UriPattern string `json:"uriPattern" gorm:"column:uri_pattern"`
	Method     string `json:"method" gorm:"column:method"`
	Sort       int    `json:"sort" gorm:"column:sort"`
}

func (d *Api) Api() string {
	return "api"
}
